//
//  CompetitionoViewC.m
//  WHSport
//
//  Created by ccjoy-jimneylee on 15/4/14.
//  Copyright (c) 2015年 jimneylee. All rights reserved.
//

#import "CompetitionoViewC.h"
#import "BusinessModel.h"
#import <UIImageView+AFNetworking.h>
#import "CompetEntity.h"
#import "ComDetailViewC.h"

@interface CompetCell : UITableViewCell
@property(nonatomic, weak) IBOutlet UIImageView *placeImg;
@property(nonatomic, weak) IBOutlet UILabel *nameLab;
@property(nonatomic, weak) IBOutlet UILabel *contLab;
@end
@implementation  CompetCell

@end

@interface CompetitionoViewC (){
    NSArray *dataArray;
}

@end

@implementation CompetitionoViewC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self getData];
    
    self.title =@"赛事";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)getData{
    
    NSString *cpage = @"1";
    [[BusinessModel sharedInstance] getCompetListWithPage:cpage getCompet:^(id info) {
        NSArray *page = [info copy];
        dataArray = page;
        [self.tableView reloadData];
    }];

}



#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100.f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        
    
    CompetCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ComCellID"
                             forIndexPath:indexPath];
    CompetEntity *comEntity = dataArray[indexPath.row];
    
    cell.contLab.text = comEntity.content;
    cell.nameLab.text = comEntity.title;
    NSString *img = [NSString stringWithFormat:@"http://218.93.12.178:8080/hhw-api/%@",
                     comEntity.picPath];
    NSURL *url = [NSURL URLWithString:img];
    [cell.placeImg setImageWithURL:url];

    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UIStoryboard *main = [UIStoryboard storyboardWithName:@"Main"
                                                   bundle:nil];
    ComDetailViewC *comvc = [main instantiateViewControllerWithIdentifier:@"ComDetailViewC"];
    comvc.comEnty = dataArray[indexPath.row];
    [self.navigationController pushViewController:comvc animated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
